<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增任务管理')" />
    <th:block th:include="include :: ztree-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-astTask-add">
            <input id="siteIds" name="siteIds"  type="hidden">
            <input id="toolListIds" name="toolListIds"  type="hidden">

            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">任务名称：</label>
                <div class="col-sm-8">
                    <input name="taskName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">任务类型：</label>
                <div class="col-sm-8">
                    <select name="taskType" class="form-control m-b" th:with="type=${@dict.getType('ast_renwu')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">任务描述：</label>
                <div class="col-sm-8">
                    <textarea name="taskDescribe" class="form-control" ></textarea>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label ">携带工具清单：</label>
                <div class="col-sm-8">
                    <select id="toolListIdsSelect" class="form-control select2-multiple" multiple>
                        <option th:each="toolList:${toolLists}" th:value="${toolList.toolId}" th:text="${toolList.toolName}" ></option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">站点选择：</label>
                <div class="col-sm-8">
                    <label class="check-box">
                        <input type="checkbox" value="1">展开/折叠</label>
                    <label class="check-box">
                        <input type="checkbox" value="2">全选/全不选</label>
                    <label class="check-box">
                        <input type="checkbox" value="3" >父子联动</label>
                    <div id="siteTrees" class="ztree ztree-border"></div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: ztree-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "asset/astTask"
        $("#form-astTask-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            var siteIds = $.tree.getCheckedNodes();
            if(siteIds){
                $("#siteIds").val(siteIds);
            }
            if ($.validate.form()) {
                var toolListIds = $.form.selectSelects("toolListIdsSelect");
                $("#toolListIds").val(toolListIds)
                $.operate.save(prefix + "/add", $('#form-astTask-add').serialize());
            }
        }

        $(function() {
            var url = ctx + "asset/astSite/treeData";
            var options = {
                id: "siteTrees",
                url: url,
                check: { enable: true,chkboxType : { "Y": "", "N": "" } },
                expandLevel: 0
            };
            $.tree.init(options);
        });

        $('input').on('ifChanged', function(obj){
            var type = $(this).val();
            var checked = obj.currentTarget.checked;
            if (type == 1) {
                if (checked) {
                    $._tree.expandAll(true);
                } else {
                    $._tree.expandAll(false);
                }
            } else if (type == "2") {
                if (checked) {
                    $._tree.checkAllNodes(true);
                } else {
                    $._tree.checkAllNodes(false);
                }
            } else if (type == "3") {
                if (checked) {
                    $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
                } else {
                    $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
                }
            }
        })

    </script>
</body>
</html>